package net.obviam.starassault.model;

import net.obviam.starassault.view.StaticTextures;

import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;

public class Block{

	private Vector2 position = new Vector2();
	private Rectangle bounds;
	private BlockType type;
	public int hitpoints;
	public enum BlockType {
		Wall, Obstacle, points
	}

	public Block(Vector2 position, BlockType type) {
		this.position = position;
		bounds = new Rectangle(position.x, position.y, 48, 48);
		hitpoints = 10;
		this.type = type;
	}

	public Vector2 getPosition() {
		return position;
	}
	
	public void setHP(int hp){
		this.hitpoints = hp;
	}
	
	public int decHP(){
		return this.hitpoints--;
	}
	
	public int getHP(){
		if(type.equals(BlockType.Obstacle)){
			return hitpoints;
		}
		else if(type.equals(BlockType.Wall)){
			return hitpoints+5;
		}
		return 0;
	}

	public boolean isBlockType(BlockType type){
		if(this.type == type){
			return true;
		}
		return false;
	}
	
	public Rectangle getBounds() {
		return bounds;
	}

	public void setBounds(float x, float y, float h, float w){
		bounds.x = x;
		bounds.y = y;
		bounds.height = h;
		bounds.width = w;

	}

	public void render(SpriteBatch sb, float ppuX, float ppuY){
		setBounds(this.position.x* ppuX, this.position.y * ppuY, ppuY, ppuX);
		if(type.equals(BlockType.Wall)){
			sb.draw(StaticTextures.blockTexture, this.position.x* ppuX, this.position.y * ppuY, ppuX, ppuY);
		}
		else if(type.equals(BlockType.Obstacle)){
			sb.draw(StaticTextures.obstBlock, this.position.x* ppuX, this.position.y * ppuY, ppuX, ppuY);
		}
		else if(type.equals(BlockType.points)){
			sb.draw(StaticTextures.blockPoints, this.position.x* ppuX, this.position.y * ppuY, ppuX, ppuY);
		}
	}

}
